package mapper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MapperHost extends MapperBase {
    private int port;
    private String appBase;
    private List<MapperContext> contexts = new ArrayList<>();

    public MapperHost(String name, String appBase, int port) {
        this.port = port;
        this.appBase = appBase;
        this.name = name;
        initContext();
    }

    private void initContext() {
        if(appBase!= null && !appBase.isEmpty()){
            File file = new File(appBase);
            if(file.exists() && file.isDirectory()){
                File[] files = file.listFiles();
                for (File f: files){
                    String contextName = f.getName();//文件夹名
                    String contextPath=f.getAbsolutePath();
                    contexts.add(new MapperContext(contextName,contextPath));
                }
            }
        }
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getAppBase() {
        return appBase;
    }

    public void setAppBase(String appBase) {
        this.appBase = appBase;
    }

    public List<MapperContext> getContexts() {
        return contexts;
    }

    public void setContexts(List<MapperContext> contexts) {
        this.contexts = contexts;
    }
}
